<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="http://www.101stratford.com/101/ebp6/style.css"/> 
<style>
a {font-size:9pt}
.tabon        {background:url(http://www.101stratford.com/webservices/images/chrome_gradient.png);}
.taboff       {background-color:#DFEAF8;border:solid 1px #c0c0c0 }
.denim        {background-color:#DFEAF8;}
.header       {border:solid 1px;border-color:white gray gray white; font-size:8pt;background-color:white } 
.titlebar     {border:solid 1px;border-color:white gray gray white; font-size:8pt;background:url(http://www.101stratford.com/webservices/images/chrome_gradient.png); } 
.datatext     {border:solid 1px;border-color:gray white white gray; font-size:8pt;background-color:white } 
.pressed      {border:solid 1px;border-color:#c090ff white white #c090ff;padding:1px;;background-color:white}
.unpressed    {border:solid 1px;border-color:white #c0c0ff #c0c0ff white;padding:1px;}
a.apressed    {font-size:8pt;text-decoration:none;color:#6699CC}
a.aunpressed  {font-size:8pt;color:#333333} 
</style>
<title>YourSQL</title>
<script language="javascript" src="http://www.101stratford.com/101/ebp6/js/xmlextras.js"></script>
<script language="javascript" src="http://www.cyber8.net/sites/bg/esp/js/mvc.js"></script> 
<script language="javascript" src="http://www.cyber8.net/sites/bg/esp/js/ajax.js"></script>
<script language="javascript" src="http://www.cyber8.net/webservices/framework/addon/treeview.js"></script> 
<script language="javascript" src="http://www.cyber8.net/webservices/framework/addon/resizer.js"></script> 
<script language="javascript" src="http://www.cyber8.net/webservices/framework/addon/toolbar.js"></script>  
<script language="javascript" src="http://www.cyber8.net/webservices/framework/addon/mouse.js"></script>  
<script language="javascript" src="http://www.cyber8.net/webservices/framework/addon/splitter.js"></script>  
<script language="javascript" src="database.js"></script>  
<script language="javascript">
var APPLICATION_NAME = document.title;
var querier = Event.create ('querier');
var main    = Event.create ('main');
var buildon = Event.create ('buildon');
var tree    = Treeview.create ('dtree');
tree.onselect = function (key) { }
tree.onchange = function (key, state) 
{ 
    var pattern,my=Controller,databases=my.databases;
    if (pattern=/dbo\.(\w+)\.(\w+)\.(\w+)/.exec(key))
    {
        var dbname   = pattern[1];
        var table    = pattern[2]; 
        var column   = pattern[3]; 
        if (state && databases[dbname].tables[table])
        {  
            databases[dbname].tables[table].selected = column;
            databases[dbname].getobject (table);
        }
        my.setobject ( column );
    }
    else if (pattern=/dbo\.(\w+)\.(\w+)/.exec(key))
    {
        var dbname   = pattern[1];
        var table    = pattern[2]; 
        if (state && databases[dbname].tables[table])
            databases[dbname].getobject (table); 
    }
    else if (pattern=/dbo\.(\w+)/.exec(key))
    { 
        var dbname   = pattern[1]; 
        my.table     = null;
        if (state && databases[dbname])
        {  
            Controller.databasename = dbname;
            databases[dbname].getobjects();
        }  
    }
    Views.treebar.invoke(); 
}

/*
* VIEWS
********************************************************************************************/
var Views = {
    footbar : View.create ('footbar', 'dfooter', function ()
    { 
        var col, name, last, count, source='/webservices/special/clean', htm=[]; 
        var query = Controller.querycollection.selected;
        if (query)
        {
            var dom       = query.result;
            var name      = query['name'];
            var elapsed   = null;
            if (!dom) return 'Query contains no records';
            var recordset = dom.getElementsByTagName ('recordset');
            for (var x=0;x< recordset.length;x++)
            {
                count     = parseInt (recordset[x].getAttribute ('count'));
                elapsed    = recordset[x].getAttribute ('elapsed');
            }
        }
        var height = Controller.hasbit( Controller.bits.FOOTVIEW ) ? 64 : 24;
        footer = { 
            maxi : function (pic, title, caption)
            { 
                htm.push ('<td>' + imagecreate(source+'/x' + height + '/'+pic) + '</td>');
                htm.push ('<td>');
                htm.push ('<font size=3 color="#000066">' + title + '</font>');
                htm.push ('<div class=small>'+caption+'<br></div>');
                htm.push ('</td>'); 
                htm.push ('<td valign="bottom" nowrap>&nbsp;&nbsp;&nbsp;');  
                htm.push ('</td>');  
            },
            mini : function (pic, title, caption)
            { 
                htm.push ('<td>' + imagecreate(source+'/x' + height + '/'+pic) + '</td>');
                htm.push ('<td class=small>');
                htm.push (''+caption+' <b>"' + title + '"</b>');
                htm.push ('</td>');  
            } 
        }
        
        var render = Controller.hasbit( Controller.bits.FOOTVIEW ) ? footer.maxi : footer.mini;
        
        htm.push ('<table cellpadding="2" cellspacing="0">');
        htm.push ('<tr>');
        if (query)
        { 
            htm.push ( render ('168x208.jpg.gif',query.name,'MySQL Query') ); 
        }
        else if (Controller.table)
        { 
            htm.push ( render ('168x208.jpg.gif',Controller.table.name,'MySQL Table') ); 
        }
        else if (Controller.databasename && Controller.databases[Controller.databasename])
        {
            htm.push ( render ('312x1008.jpg.gif',Controller.databasename,'MySQL Database Connection') ); 
        } 
        else
        { 
            htm.push ('<td valign="bottom">' + imagecreate(LOGO_URL,null,height) + '</td>');  
        }
        
        if (query && count)
        {
            var next,prev,cursor,size = parseInt(query.pagesize),suffix={left:{x:'',f:null},right:{x:'',f:null}}; 
            var re=function(n,v) { return '<tr><td nowrap class="small">'+n+
                                          ':</td><td class="small" width="100%"'+
                                          ' align="right">'+v+'</td></tr>'; };
            next=parseInt(query.position)+parseInt(size);if(next>count)next=count;
            prev=query.position-size;
            cursor            = Controller.hasbit( Controller.bits.SCALAROUTPUT ) ? query.selected : query.position;
            suffix.right.x    = next==count?'.off':''
            suffix.left.x     = prev<0?'.off':''
            suffix.right.f    = next==count?imagecreate:imagelink;
            suffix.left.f     = prev<0?imagecreate:imagelink;
            htm.push ('<td nowrap valign="top">');
            htm.push ('<table width="100">');
            if (Controller.hasbit( Controller.bits.FOOTVIEW ))
            {
                htm.push ( re ('Total rows', count) );
                htm.push ( re ('Starting at', parseInt(cursor) + 1) );
                if (!Controller.hasbit( Controller.bits.SCALAROUTPUT ))
                    htm.push ( re ('to', next) );
            }
            htm.push ('</tr></table>');
            htm.push ('</td>');
            htm.push ('<td nowrap '+(Controller.hasbit( Controller.bits.FOOTVIEW )?'valign="top"':'')+'>');
            htm.push ('&nbsp;&nbsp;');
            if (count > size)
            {
                htm.push ('<select onchange=\'Controller.reopenobject("' + query.key +'", this.value)\'>');
                for (var x=0;x<count;x+=size)
                {
                    last=x+size;if(last>count)last=count;
                    htm.push ('<option '+ sel (query.position==x)+' value="' + x + '">' + (x+1) + ' to ' + last);
                }
                htm.push ('</select>');
                htm.push (' of ');
            }
            htm.push ('' + count + ' records');
            
            if (!Controller.hasbit( Controller.bits.SCALAROUTPUT ))
            {
                if (Controller.hasbit( Controller.bits.FOOTVIEW ))
                {
                    htm.push (', <br>&nbsp;&nbsp;<input onchange="Controller.resetobject(this.value)"');
                    htm.push (' size="3" value="'+size+'"/> per page.');
                }
                else
                {
                    suffix.left.f  = function (ignore, command) { return textlink ('&#171;back', command, suffix.left.x=='.off'?'color:gray':''); }
                    suffix.right.f = function (ignore, command) { return textlink ('next&#187;', command, suffix.right.x=='.off'?'color:gray':''); }
                }
            } 
            else
            { 
                suffix.left.f  = function (x) { return imagelink(x,'Controller.querycollection.selected.advance(-1)'); } 
                suffix.right.f = function (x) { return imagelink(x,'Controller.querycollection.selected.advance(1)'); } 
                suffix.right.x = cursor>count-2?'.off':''
                suffix.left.x  = cursor<1?'.off':''
            }
            htm.push ('&nbsp;');
            htm.push ('</td>');
            htm.push ('<td nowrap '+(Controller.hasbit( Controller.bits.FOOTVIEW )?'':'')+'>');
            //if (Controller.hasbit( Controller.bits.FOOTVIEW ))
            //{ 
                htm.push ('<table><tr>');
                htm.push ('<td>' + suffix.left.f ('/webservices/images/fancy.left'+suffix.left.x+'.png', 
                                        'Controller.reopenobject ("' + query.key +'", '+prev+')') + '</td>');
                htm.push ('<td>' + suffix.right.f ('/webservices/images/fancy.right'+suffix.right.x+'.png', 
                                        'Controller.reopenobject ("' + query.key +'", '+next+')') + '</td>');
                htm.push ('<td class="small" valign=bottom style="color:gray">&nbsp;&nbsp;&nbsp;&nbsp;' + elapsed + ' secs</td>');
                htm.push ('</tr></table>');
            //}
            htm.push ('</td>');
        }
        htm.push ('</tr>');
        htm.push ('</table>');
        return htm.join (''); 
       
    }, null, function () { window.resizeListener.invoke (); }) ,
    /*........................................................................................*/
    navbar : View.create ('navbar', 'dnavbar', function ()
    { 
        var widget    = '/webservices/images/geo_ad_close_widg2.gif';
        var query     = Controller.querycollection.selected
        var queries   = Controller.querycollection.items, htm=[];
        var ok,q,key  = query ? query.key : ''; 
        htm.push ('<table cellpadding="4" cellspacing="0"><tr>');
        for (var x in queries)
        {
            q  = queries[x];
            ok = q.key == key && Event.selected==querier.name;
            htm.push ('<td bgcolor="'+(ok?'white':'')+'" title="' + q.key + '" class=small >');
            if (ok) htm.push (q.name);
            else htm.push (textlink (q.name, 'Controller.openquery("' + q.key + '")', 'font-size:8pt'));
            htm.push (imagelink (PIC_ROOT+widget, 'Controller.removequery("' + q.key + '")'));
            htm.push ('</td>');
        }
        htm.push ('</tr></table>');
        return htm.join ('');
    }),
    /*........................................................................................*/
    toggler : View.create ('toggler', 'dsplitter', function ()
    { 
        var treebit = Controller.getbit( Controller.bits.TREEVIEW ); 
        var active  = Controller.hasbit( Controller.bits.TREEVIEW ); 
        return '<img src="'+PIC_ROOT+'/webservices/images/clear.gif" width=8>'; 
        return imagelink (PIC_ROOT+'/webservices/images/close_' + 
                             (active ? 'off' : 'on') + '.gif', 
                           'Controller.setvalue("viewas", '+treebit+')'
                         ); 
    },null,function () { 
        var active  = Controller.hasbit( Controller.bits.TREEVIEW ); 
        window.resizeListeners['dtree'].offsetX = active ? (Controller.treewidth + 'px') : '0px'
        window.resizeListener.invoke (); 
    }),
    /*........................................................................................*/
    vtoggler : View.create ('vtoggler', 'dvsplitter', function ()
    { 
        var footbit = Controller.getbit( Controller.bits.FOOTVIEW ); 
        var active  = Controller.hasbit( Controller.bits.FOOTVIEW ); 
        return imagelink (PIC_ROOT+'/webservices/images/close_' + 
                             (active ? 'down' : 'up') + '.gif', 
                           'Controller.setvalue("viewas", '+footbit+')'
                         ); 
    },null,function ()   
    {    
        var active  = Controller.hasbit( Controller.bits.FOOTVIEW ); 
        window.resizeListeners['dbody'].offsetY = active ? 100 : 40;
        window.resizeListeners['dtree'].offsetY = active ? 100 : 40;
        window.resizeListener.invoke ();  
    }),
    /*........................................................................................*/
    qtoggler : View.create ('qtoggler', 'dqsplitter', function ()
    { 
        if (Event.selected!=querier.name) return ''; 
        if (!Controller.querycollection.selected.SQLON) return ''; 
        return '<img src="'+PIC_ROOT+'/webservices/images/clear.gif" width=8>'; 
        return '<img onload="window.resizeListener.invoke()"' + 
                ' onclick="Controller.querycollection.selected.sql()"' + 
                ' src="'+PIC_ROOT+'/images/toggle.gif"/>';  
    }),
    /*........................................................................................*/
    treebar : View.create ('treebar', 'dtree', function ()
    { return Controller.hasbit( Controller.bits.TREEVIEW ) ? tree.draw(true) : '';
    },null,function () { window.resizeListener.invoke (); }) 
    /*........................................................................................*/
}
 

 
 
  
 

var toolbar = View.create ('toolbar', 'daddress', function ()
{ 
    var vue, htm = [], has=Controller.hasbit, anti=Controller.getbit, bit=Controller.bits;
    var query      = Controller.querycollection.selected, queries = Controller.querycollection.items
    var dbname     = query ? query.database.name : '';
    var reline     = function (x) { return Controller.hasbit (x) ? 'text-decoration:line-through' : ''; };
    var arrow      = function (x) { return Controller.hasbit (x) ? '&#171;' : '&#187;'; }; 
    var redo       = function (x,v) { return 'Controller.setvalue("viewas", ' + anti(x) + (v?', '+v:'') + ')'; }
    var database   = Controller.databases[Controller.databasename];  
    var tb=Toolbar(PIC_ROOT, 'window.resizeListener.invoke()');
  
    tb.store ('back', '/webservices/images/backbutton.png');
    tb.store ('new', '/webservices/images/explorer/new.gif');
    tb.store ('query', '/webservices/images/edit.gif');
    tb.store ('table', '/webservices/images/ico_grid.jpg');
    tb.store ('db', '/webservices/images/s_db.png');
    tb.store ('sql', '/webservices/images/xui.view.gif');
    tb.store ('output', '/webservices/images/view.gif');
    tb.store ('grid', '/webservices/images/table.gif');
    tb.store ('text', '/webservices/images/explorer/NOTE08.ICO.gif');
    tb.store ('exclaim', '/webservices/images/explorer/alerticon.jpg');
    tb.store ('build', '/webservices/images/xui.graph.gif');
    tb.store ('open', '/webservices/images/explorer/icon_book.gif');
    tb.store ('addcolumn', '/webservices/images/icon_addtoplaylist.gif');
    tb.store ('rename', '/webservices/images/explorer/input_icon.gif');
    tb.store ('remove', '/webservices/images/delete.gif');
    tb.store ('scalar', '/webservices/images/pda/pda_card.gif');
    tb.store ('spacer', '/webservices/images/clear.gif');
    tb.store ('options', '/webservices/images/i.p.folder.drafts.gif');
    tb.store ('caption', '/webservices/images/explorer/smKeyWord.gif');
    tb.store ('refresh', '/webservices/images/explorer/refresh.gif');
    tb.store ('fclose', '/webservices/images/explorer/fclosexp.gif');
    tb.store ('export', '/webservices/images/explorer/move_to.gif')
    tb.store ('process', '/webservices/images/explorer/tree_edit.gif');
    tb.texton = has (bit.SHOWCAPTIONS);
    
    htm.push ('<table cellpadding="0" cellspacing="0"><tr><td nowrap valign=top>');  
                                 
    if (Event.selected==querier.name)
    {
        tb.add ('back', 'Controller.querycollection.select(null);', 'back'); 
    }
    
    tb.add ('new', redo (bit.CREATENEW), 'new'+arrow (bit.CREATENEW), has (bit.CREATENEW)); 
    if (has (bit.CREATENEW))
    {  
        if (database)
        {
            tb.add ('query', 'Controller.newquery("' + Controller.databasename + '")', 'new query'); 
            tb.add ('table', 'Controller.newtable()', 'new table'); 
        } 
        tb.add ('db', 'Controller.newdb()', 'new connection');
        tb.add ('spacer');  
    }
    tb.add ('refresh', 'location.reload()', 'refresh');
    tb.add ('fclose', redo (bit.TREEVIEW),'folders',has(bit.TREEVIEW)); 
 
    if (Event.selected==querier.name)
    {
        tb.add ('sql', 'Controller.querycollection.selected.sql()', 
                'SQL' + (query.SQLON?'&#171;':'&#187;'), query.SQLON); 
                
        
        tb.add ('output', redo (bit.SHOWOUTPUT, 'toolbar'), 
                'output as'+arrow (bit.SHOWOUTPUT), has(bit.SHOWOUTPUT)); 
                                    
        if ( has (bit.SHOWOUTPUT) )
        {  
            tb.add ('grid', 'Controller.setbit('+bit.TEXTOUTPUT+', false)', 'grid', !has(bit.TEXTOUTPUT)); 
            tb.add ('text', 'Controller.setbit('+bit.TEXTOUTPUT+', true)', 'text', has(bit.TEXTOUTPUT)); 
            tb.add ('scalar', redo (bit.SCALAROUTPUT), 'scalar', has(bit.SCALAROUTPUT)); 
            tb.add ('spacer');
        }
         
         
        tb.add ('exclaim', 'Controller.execquery()', 'execute', ! Controller.querycollection.selected.SQLON); 
        tb.add ('build', redo (bit.BUILDQUERY), 
                'build' + arrow (bit.BUILDQUERY), has(bit.BUILDQUERY)); 
    }
    
    if (Event.selected==main.name)
    {  
        if (Controller.table)
        {  
            tb.add ('open', 'Controller.openobject("' + Controller.table.name + '", ' + 
                    'null, "'+database.name+'")', 'open table'); 
            tb.add ('addcolumn', 'Controller.addcolumn()', 'add field'); 
            tb.add ('rename', 'Controller.renametable()', 'rename'); 
            tb.add ('remove', 'Controller.deletetable()', 'delete'); 
            tb.add ('export', 'Controller.exportquery ("'+database.name+'")', 'export data', database.SHOWEXPORT);
            tb.add ('export', 'Controller.backupobject ()'); 
        }  
        else if (database)
        {  
            tb.add ('options', 'Controller.databases["'+database.name+'"].setoptions()', 'connection options', database.SHOWOPTIONS);
            tb.add ('process', 'Controller.showprocesses("'+database.name+'")', 'processes');
        }
    }
    tb.add ('caption', redo (bit.SHOWCAPTIONS, 'toolbar'), null, has(bit.SHOWCAPTIONS)); 
    
    htm.push ( tb.draw() ) ; 
    htm.push ('</td>') ; 

    htm.push ('<td valign=top nowrap>&nbsp;');
    htm.push ('<select '+(query?'':'disabled')+'');
    htm.push (' onchange=\'Controller.querycollection.selected.database=Controller.databases[this.value]\'');
    htm.push ('><option value="">(choose)'); 
    for (var x in Controller.databases)
        htm.push ('<option '+sel(x==dbname)+' value="'+x+'">'+x+'</option>')
    htm.push ('</select>&nbsp;</td>');
    
    htm.push ('<td nowrap valign=top>') ; 
    htm.push ('  <div id="tbo" ');
    htm.push ('   style="width:355px;overflow:hidden;');
    htm.push ('          border:solid 1px;');
    htm.push ('          border-color:gray white white gray;');
    htm.push ('          padding-left:4px;');
    htm.push ('          background-color:#f0f0f0">');
    if (Controller.databasename && Controller.databases[Controller.databasename])
    {
        htm.push ('<table cellspacing=0 cellpadding=0><tr><td>');
        htm.push ( imagecreate ('/webservices/images/s_db.png') ); 
        htm.push ('&nbsp;</td>'); 
        htm.push ('<td nowrap="nowrap">');
        htm.push ('<div id="tbi" ');
        htm.push (' style="width:300px;overflow:hidden;');
        htm.push ('        background-color:#f0f0f0">' + tree.getpath() + '</div>'); 
        htm.push ('</td>') ;
        htm.push ('</tr></table>') ;
    }
    else htm.push ('<font color="gray">No connection selected</font>');    
    htm.push ('</div>') ;
    htm.push ('</td>') ;
    htm.push ('</tr></table>');
    return htm.join ('');
},null,function ()
{
    Resizer ('tbo', 10);
    Resizer ('tbi', 36);
    window.resizeListener.invoke ();
});

var workspace = View.create ('pane', 'dbody', function ()
{ 
    var htm=[];
    if (Controller.databases.count==0)
    {
        htm.push ('<blockquote>');
        htm.push ('<table width=500 bgcolor="#FFFFCC" style="border:solid 1px gray"><tr><td>');
        htm.push ('<img src="'+PIC_ROOT+'/webservices/images/Emblem-important-red.png" align=left>');
        htm.push ('No connections have been created. To create a connection to your MySQL database, click the ');
        htm.push (imagelink(PIC_ROOT+'/webservices/images/s_db.png','Controller.newdb()','new connection'));
        htm.push (' button.');
        htm.push ('</td></tr></table>');
        htm.push ('</blockquote>');
        return htm.join ('');
    }
    
    if (Controller.table) 
    {
        htm.push ('<table cellspacing="0" style="border:solid 1px;border-color:gray #f0f0f0 #f0f0f0 gray">');
        htm.push ('<tr>');
        htm.push ('<td colspan="2" style="background-color:#e0e0e0" class=titlebar>&nbsp;</td>'); 
        htm.push ('<td class=titlebar style="background-color:#e0e0e0" nowrap>name</td>');
        htm.push ('<td class=titlebar style="background-color:#e0e0e0" nowrap>type</td>');
        htm.push ('<td class=titlebar style="background-color:#e0e0e0" nowrap>size</td>');
        htm.push ('<td class=titlebar style="background-color:#e0e0e0" nowrap>allow null</td>');
        htm.push ('<td class=titlebar style="background-color:#e0e0e0" nowrap>key</td>');
        htm.push ('<td class=titlebar style="background-color:#e0e0e0" nowrap>primary</td>');
        htm.push ('<td class=titlebar style="background-color:#e0e0e0" nowrap>default value</td>'); 
        htm.push ('<td class=titlebar style="background-color:#e0e0e0" width="100%">&nbsp;</td>'); 
        htm.push ('</tr>');
        for (var x in Controller.table.columns)
        {
            htm.push (Controller.table.columns[x].draw(Controller.table.selected));
        }
        htm.push ('</table>');
    }
    else if (Controller.databasename && Controller.databases[Controller.databasename])
    {
        var database = Controller.databases[Controller.databasename];
        if (database.SHOWOPTIONS)
        {
            htm.push ('<blockquote><h3>'+database.name+' Settings</h3>');
            htm.push ('<table>');
            var d=function (x) {return '<tr><td align=right>'+this.name+'</td><td><input '+
            'onchange=\'Controller.databases[Controller.databasename]["'+this.key+'"]=this.value\' '
            +' id="i'+this.name+'" type="'+this.type+'" value="'+x+'"></td></tr>';}
            var o=[
                 {key: 'name', name : 'Database', type : 'text', draw : d},
                 {key: 'server', name : 'Host Name', type : 'text', draw : d},
                 {key: 'username', name : 'Username', type : 'text', draw : d},
                 {key: 'password', name : 'Password', type : 'password', draw : d}  
            ];
            for (var x in o)
            {
                htm.push (o[x].draw (database[o[x].key]));
            }
            htm.push ('<tr><td colspan=2 align=right>' );
            htm.push ('<input onclick="Controller.databases[Controller.databasename].save()"' );
            htm.push (' type=button value="Save Settings">' );
            htm.push ('<input onclick="Controller.databases[Controller.databasename].destruct()"' );
            htm.push (' type=button value="Delete Connection">' );
            htm.push ('</td></tr>' );
            htm.push ('</table>');
            htm.push ('</blockquote>');
        }
        
        if (database.SHOWEXPORT)
        {
            htm.push ('<blockquote><h3>Export '+database.name+'</h3>');
            htm.push ('<table>'); 
            htm.push ('<tr>'); 
            htm.push ('<td valign="top"></td>'); 
            htm.push ('<td valign="top">'); 
            htm.push ('<textarea rows=20 cols=50>'); 
            htm.push (''); 
			for (var x in database.tables) htm.push (database.tables[x].doexport()); 
            htm.push ('</textarea>'); 
            htm.push ('</td>'); 
            htm.push ('</tr>'); 
            htm.push ('</table>');
            htm.push ('</blockquote>');
        }
        
        var row=[];
        for (var x in database.tables) row.push (database.tables[x].draw()); 
        if (row.length > 0)
        {
            htm.push ('<table cellspacing="0" style="border:solid 1px;border-color:gray #f0f0f0 #f0f0f0 gray">');
            htm.push ('<tr>');
            htm.push ('<td colspan="3" style="background-color:#e0e0e0" class=titlebar>&nbsp;</td>'); 
            htm.push ('<td class=titlebar style="background-color:#e0e0e0" nowrap>name</td>');
            htm.push ('<td class=titlebar style="background-color:#e0e0e0" nowrap>type</td>');
            htm.push ('<td class=titlebar style="background-color:#e0e0e0" nowrap>size</td>');
            htm.push ('<td class=titlebar style="background-color:#e0e0e0" nowrap>overhead</td>');
            htm.push ('<td class=titlebar style="background-color:#e0e0e0" nowrap>date created</td>');
            htm.push ('<td class=titlebar style="background-color:#e0e0e0" nowrap>last updated</td>');
            htm.push ('<td class=titlebar style="background-color:#e0e0e0" width="100%">&nbsp;</td>'); 
            htm.push ('</tr>');
            for (var x in database.tables) htm.push (database.tables[x].draw());
            htm.push ('</table>');
        } else htm.push (database.name + ' has no tables');
    }
    else return wait_message( '' );
    return htm.join (''); 
});



var querytext = View.create ('querytext', 'dquerybar', function ()
{
    if (Event.selected!=querier.name) return '';
    if (!Controller.querycollection.selected) return 'No query selected';
    var query = Controller.querycollection.selected;
    if (!query.SQLON) return '';
    return '<textarea class="flat" id="tq'+query.key+'" rows="25">'+query.text+'</textarea>';
},null,function ()
{
    if (!Controller.querycollection.selected) return 'No query selected';
    var query = Controller.querycollection.selected;
    if (query) Resizer ('tq'+query.key+'', 10, query.height+'px');
    window.resizeListener.invoke ();
});

var querypane = View.create ('query', 'dbody', function ()
{ 
    var col, name, size, pos, lf='\n', NULL='<em>NULL</em>', render, record, htm=[];
    if (!Controller.querycollection.selected) return 'No query selected';
    var query     = Controller.querycollection.selected;
    var dom       = query.result;
    var cursor    = query.selected < 0 ? 0 : query.selected;
    if (!dom) return 'Query contains no records';
    var records   = dom.getElementsByTagName ('record');
    var f,faults  = dom.getElementsByTagName ('fault');
    var toinput   = function (x,f,i) { return '<td bgcolor="#336699">'+
        '<input onchange="bind2Ajax(this)" class=datatext id="'+f+'.'+i+'" value="'+
        (x==NULL?'':x)+'" size="'+Math.min(x.length,255)+'"></td>'; };
    var tovalue   = function (x) { return '<td nowrap class="header">'+x+'&nbsp;</td>'; };
     
    if (faults.length)
    {
        var err=['query','mysql_errno','mysql_error'];
        htm.push ('<table width=500 bgcolor="#FFFFCC" style="border:solid 1px gray"><tr><td>');
        htm.push ('<img src="'+PIC_ROOT+'/webservices/images/Emblem-important-red.png" align=left>');
        for (var e in err)
        {
             f=dom.getElementsByTagName (err[e]);
             for (var x=0;x<f.length;x++)
             {
                  if (f[x].firstChild)
                     htm.push ('<b>'+err[e]+'</b>: <code>'+f[x].firstChild.nodeValue+'</code><br>');
             }
        }
        htm.push ('</td></tr></table>');
        htm.push ('<small style=color:gray>The query returned an error. Please check your SQL syntax and try again.</small>');
        return htm.join ('');
    }    
    
    if (Controller.hasbit( Controller.bits.TEXTOUTPUT ))
    {
        htm.push ('<xmp>');
        htm.push (' #' + repeat (' ', 8) + ' ');
    }
    else
    {
        htm.push ('<table cellspacing=0 cellpadding=2 bgcolor="#c0c0c0">');
        if (!Controller.hasbit( Controller.bits.SCALAROUTPUT ))
            htm.push ('<tr><td style="background-color:#e0e0e0" class="header">&nbsp;</td>');
    }
    
    if (records.length)
    { 
        if (Controller.hasbit( Controller.bits.SCALAROUTPUT ))
        {
            record = records[cursor]; 
            if (!record) return 'No current record ' + cursor;
            col=record.childNodes;
            render = function (x,f,i) { return '<tr><td style="background-color:#e0e0e0" class="header">'+
                f+'</td><td class="header"><input size="50" value="'+(x==NULL?'':x)+'"></td></tr>'; }
            for (var i=0;i<col.length;i++)
            {
                if(col[i].nodeName=='field')
                {
                    name = col[i].getAttribute ("name");
                    size = col[i].getAttribute ("size");
                    value = col[i].firstChild ? col[i].firstChild.nodeValue : NULL;
                    if (Controller.hasbit( Controller.bits.TEXTOUTPUT ))
                    {
                        htm.push (pad (value, size) + ' ');
                    }

                    else
                    {
                        htm.push ( render(value, name, x) );
                    } 
                }
            }
            htm.push ( '</table>' );
            return htm.join ('');
        }
    
        var u, text, underline=[repeat ('-', 10) + ' '];
        col=records[0].childNodes;
        for (var i=0;i<col.length;i++)
        {
            if(col[i].nodeName=='field')
            {
                name = col[i].getAttribute ("name");
                size = col[i].getAttribute ("size");
                if (Controller.hasbit( Controller.bits.TEXTOUTPUT ))
                { 
                    u=repeat ('-', size);
                    htm.push (pad (name+'('+size+')', size) + ' ');
                    underline.push (pad(u, size) + ' ');
                }
                else
                {
                    htm.push ('<td style="background-color:#e0e0e0" nowrap class="header">' + name + '&nbsp;</td>');
                } 
            }
        }
        
        if (Controller.hasbit( Controller.bits.TEXTOUTPUT ))
        {
            htm.push (lf + underline.join ('') + lf); 
        }
        else
        {
            htm.push ('</tr>');
        } 
        
        for (var x=0;x<records.length;x++)
        {
            pos    = x+1+parseInt(query.position)
			text   = textlink(pos,'Controller.querycollection.selected.select('+pos+')');
            render = pos==query.selected ? toinput : tovalue;
            if (Controller.hasbit( Controller.bits.TEXTOUTPUT ))
            {
                htm.push (' ' + pad (pos.toString(), 9) + ' ');
            }
            else
            {
                htm.push ('<tr><td align=right style="background-color:#e0e0e0" class="' + 
				   (pos==query.selected?'':'header') + '">' + text + '</td>');  
            } 
            
            col=records[x].childNodes;
            for (var i=0;i<col.length;i++)
            {
                if(col[i].nodeName=='field')
                {
                    name = col[i].getAttribute ("name");
                    size = col[i].getAttribute ("size");
                    value = col[i].firstChild ? col[i].firstChild.nodeValue : NULL;
                    if (Controller.hasbit( Controller.bits.TEXTOUTPUT ))
                    {
                        htm.push (pad (value, size) + ' ');
                    }

                    else
                    {
                        htm.push ( render(value, name, x) );
                    } 
                }
            }
            if (Controller.hasbit( Controller.bits.TEXTOUTPUT ))
            {
                htm.push (lf); 
            }
            else
            {
                htm.push ('</tr>');
            } 
        }
    } else return 'Query returned no records';
    
    if (Controller.hasbit( Controller.bits.TEXTOUTPUT ))
    {
        htm.push ('</xmp>');
    }
    else
    {
        htm.push ('</table>');
    } 
    return htm.join ('');
});


var buildquery = View.create ('buildquery', 'qbfieldlist', function ()
{ 
    var htm=[],query=Controller.querycollection.selected;
    if (Controller.hasbit( Controller.bits.BUILDQUERY ) && Event.selected == querier.name)
    {
        var database = query.database;
        htm.push ('<div id="qbuilder" style="width:160px;height:'+query.height+'px;background-color:white;border:solid 1px silver;overflow:auto;padding:2px">'); 
        htm.push ('<table cellpadding="2" width="100%" cellspacing="0"><tr><td style="color:#666" nowrap>'); 
        if (Controller.querytable)
        {
            htm.push ('<div style="background-color:#FFFFCC;padding:4px">');
            htm.push (textlink('&#171;back', 'Controller.setvalue ("querytable", null)'));
            htm.push ('</div>');
            var columns = database.tables[Controller.querytable].columns;
            for (var x in columns)
            {
                htm.push ('<input type=checkbox '+chk(query.hascolumn(Controller.querytable,columns[x].name))+' ');
                htm.push (' onclick=\'Controller.querycollection.selected.addcolumn("' + Controller.querytable + '","' + columns[x].name + '")\'');
                htm.push (' >'); 
                htm.push (columns[x].name);
                htm.push ('<br>');
            }
        }
        else
        {
            for (var x in database.tables)
            {
                htm.push ('<input type=checkbox '+chk( query.builder.tables[database.tables[x].name] )+' ');
                htm.push (' onclick=\'Controller.querycollection.selected.deltable("' + database.tables[x].name + '")\'');
                htm.push (' >'); 
                htm.push (textlink(database.tables[x].name, 
                                 'Controller.querycollection.selected.add ("'+database.tables[x].name+'")'
                                ) ); 
                htm.push ('<br>');
            }
        }
        htm.push ('</td></tr></table></div>');
    }
    return htm.join ('');
});
//
main.add (buildquery, querytext, workspace, toolbar);
querier.add (buildquery, querytext, querypane, toolbar);
for (var x in Views)
{
    main.add (Views[x]);
    querier.add (Views[x]);
}
 
/*
* CONTROLLER EVENTS
********************************************************************************************/
Controller.ondatabaseloaded = function (data)
{
    var name, dom=XmlDocument.create();   
    if (dom.loadXML (data))  
    { 
        var my, key,tablename = null;
        var tables = dom.getElementsByTagName ('tables');
        var nodename = 'dbo.' + Controller.databasename;
        tree.items[nodename].clear();
        if (tables.length == 0) 
        {
            main.invoke ();
            return confirm ('No tables where found in the request.');
        }
        
        for (var x=0;x<tables.length;x++) Controller.databasename=tables[x].getAttribute ('database');
          
        var table = dom.getElementsByTagName ('table');
      
        document.title = APPLICATION_NAME + ' - ' + nodename;
        for (var x=0;x<table.length;x++)
        {  
            tablename = table[x].getAttribute ('name')
            key  = nodename + '.' + tablename
            tree.add (tablename, key, nodename);
            tree.items[key].icon=imagecreate ('/webservices/images/ico_grid.jpg');
            tree.add ('loading...', key + '/sub', key); 
            Controller.databases[ Controller.databasename ].tables [ tablename ] = 
                Table.create(table[x], Controller.databases[ Controller.databasename ]); 
        }
        main.invoke ();
    }     else { var k=window.open();k.document.write (data)}
}

Controller.ontable = function (data, callback)
{
 
    var dbname, attach, column, name, key, dom=XmlDocument.create();   
    Controller.querycollection.selected = null;
    if (dom.loadXML (data))  
    { 
        var tables  = dom.getElementsByTagName ('table');
        var columns = dom.getElementsByTagName ('column');
             
        for (var x=0;x<tables.length;x++)
        {  
            dbname = tables[x].getAttribute ('database'); 
            name   = tables[x].getAttribute ('name');
        }
        
        attach = 'dbo.' + dbname + '.' + name; 
        tree.items[attach].clear(); 
        
        document.title = APPLICATION_NAME + ' - ' + attach;
        Controller.databasename     = dbname;      
        Controller.table             = Controller.databases[dbname].tables[name];
        Controller.table.columns     = [];
        for (var x=0;x<columns.length;x++)
        {  
            name       = columns[x].getAttribute ('name'); 
            key        = attach + '.' + name;
            column     = Column.create(columns[x], attach);
            desc    = '<b class=small>' + column.type + (column.size&&column.size.length>0?' ('+column.size+')':'') + '</b>';
            tree.add (name + ' ' + desc, key, attach);
            tree.items[key].icon='<img src="' + PIC_ROOT + '/webservices/images/i.s.property.gif" align="absmiddle">';
            if (column.key && column.key.length > 0) Controller.table.key = name;
            Controller.table.columns.push ( column );
        }
        if (callback && typeof(callback)=='function') return callback();
        main.invoke ();
    }
}

Controller.onopen = function (data)
{ 
    var attach, name, dom=XmlDocument.create();   
    if (dom.loadXML (data))  
    {  
        Controller.recordset = dom;
        querier.invoke ();
    }
}

/*
* CONTROLLER METHODS
********************************************************************************************/
Controller.deletetable = function ()
{
    if (Controller.databasename && Controller.databases[Controller.databasename])
        Controller.databases[Controller.databasename].remove (Controller.table.name);
}

Controller.newtable = function ()
{
    var x;
    if (x=prompt('Enter a name for the new table'))
    {
        if (Controller.databasename && Controller.databases[Controller.databasename])
            Controller.databases[Controller.databasename].add (x);
    }
    Controller.setbit (Controller.bits.CREATENEW, false);
}

Controller.newdb = function ()
{
    var x;
    if (x=prompt('Enter a database name for the new connection'))
    { 
        Controller.databases[x]=Database.create (x);
        Controller.databases[x].SHOWOPTIONS=true;
        Controller.databases.count++;
        Controller.databasename = x;
    }
    Controller.setbit (Controller.bits.CREATENEW, false);
    main.invoke ();
}

Controller.renametable = function ()
{
    var x;
    if (x=prompt('Enter a new name for the "'+Controller.table.name+'" table', Controller.table.name))
    {
        if (Controller.databasename && Controller.databases[Controller.databasename])
            Controller.databases[Controller.databasename].rename (Controller.table.name, x);
    }
}

Controller.newquery = function (dbname)
{
    var i = Controller.querycollection.items.length + 1;
    var name = "Query " + i;
    var o = Controller.addquery ('', name, Controller.databases[dbname]);
    Controller.querycollection.selected = o;
    Controller.setbit (Controller.bits.CREATENEW, false);
    querier.invoke(); 
}

Controller.exportquery = function (dbname)
{
    var i = Controller.querycollection.items.length + 1;
    var name = "Export " + Controller.table.name;
    var o = Controller.addquery (Controller.table.doexport(), name, Controller.databases[dbname]);
    Controller.querycollection.selected = o; 
    querier.invoke(); 
}

Controller.addquery = function (text, name, database)
{
    var o = Query.create (text, name, database); 
    if (Controller.querycollection.keys[o.key])
    {
       return Controller.querycollection.keys[o.key];
    }
    o.id = Controller.querycollection.items.length;
    Controller.querycollection.items.push (o);
    Controller.querycollection.keys[o.key] = o;
    return o;
}

Controller.openquery = function (name)
{
    Controller.querycollection.selected = Controller.querycollection.keys[name];
    querier.invoke();
}

Controller.execquery = function ()
{
   var o=Controller.querycollection.selected;
   var e=document.getElementById ('tq'+o.key);
   if (e)
   {
        show_wait_message ('executing query...');
        o.text = e.value;
        o.invoke ();
   }
}

Controller.removequery = function (x)
{
    var i=0,o=[], queries=Controller.querycollection.items; 
    Controller.querycollection.selected=null;
    for (var e in queries)
    { 
        if (queries[e].key!=x) 
        {
            o[queries[e].key]=queries[e];
            Controller.querycollection.selected=queries[e];
            i++;
        }
    }
    Controller.querycollection.items = o;
    var view = i > 0 ? querier : main;
    view.invoke();
}

Controller.openobject = function (name, key, dbname)
{
    show_wait_message ('loading '+name+'...');
    var object = Controller.addquery ("SELECT * FROM " + name, name, Controller.databases[dbname]);
    object.position = key ? key : 0;
    object.invoke ();
} 

Controller.showprocesses = function (dbname)
{
    show_wait_message ('loading processes from '+dbname+'...');
    var object = Controller.addquery ("SHOW PROCESSLIST ", dbname + ' processes', Controller.databases[dbname]);
    object.invoke ();
} 

Controller.backupobject = function ()
{
    show_wait_message ('backing up '+Controller.table.name+'...');
    Controller.table.backupobject(0);
} 

Controller.resetobject = function (size)
{
    show_wait_message ('repaging '+name+'...');
    var object=Controller.querycollection.selected;
    if (!object) return false;
    object.pagesize = size;
    object.position = 0;
    object.invoke ();
} 

Controller.reopenobject = function (name, key)
{
    show_wait_message ('reloading '+name+'...');
    var object = Controller.querycollection.keys[name];
    if (!object) return false;
    object.position = key ? key : 0;
    object.invoke ();
}

Controller.setobject = function (name)
{
    Controller.table.selected = name;
    main.invoke()
}

Controller.getobject = function (key)
{    
    Webservice.getobject ("table", key);
}

Controller.addcolumn = function ()
{  
    var x;
    if (x=prompt('Enter a name for the new field'))
        Controller.table.add (x);
}
 
Controller.savecolumn = function ()
{    
    var column=Controller.table.columns;
    for (var x in column)
    {
        if (column[x].originalname==Controller.table.selected) 
            return column[x].save();
    }
}

Controller.oncookie = function (data)
{  
    var dom=XmlDocument.create();   
    if (dom.loadXML (data))  
    {   
        var name, value, add = dom.getElementsByTagName ('add');   
        for (var x=0;x<add.length;x++)
        {  
            name = add[x].getAttribute ('name');
            if (add[x].firstChild)
                cookie[name]=add[x].firstChild.nodeValue;
        }  
        if (cookie.viewas) Controller.viewas = cookie.viewas;
        if (cookie.treewidth) Controller.treewidth = cookie.treewidth;
    }  
    beginRender () ;
}
/*
* CONTROLLER PROPERTIES
********************************************************************************************/
Controller.querycollection = {
    index : -1,
    selected : null,
    select : function (x) { this.selected=x;main.invoke();},
    items : [],
    keys: {}
}
Controller.firstkey     = 0;
Controller.lastkey      = 0;
Controller.keypage      = [];
Controller.table        = null;
Controller.tables       = {};
Controller.databases    = {};
Controller.pagesize     = 100;
Controller.treewidth    = 200;

var bits=['TREEVIEW','CREATENEW','FOOTVIEW','SHOWOUTPUT','TEXTOUTPUT','BUILDQUERY','SCALAROUTPUT','SHOWCAPTIONS'];  
Controller.bits={};for (var x=0;x<bits.length;x++) Controller.bits[ bits[x] ] = Math.pow (2,x);
Controller.getbit = function(i){ return Controller.hasbit(i)  ? Controller.viewas - i  : Controller.viewas - (-i);};
Controller.setbit = function(i,on){ var o=Controller.hasbit(i); if (!(o&&on)) Controller.setvalue('viewas',Controller.getbit(i)); };
Controller.hasbit = function(i){ return Controller.viewas & i;};
Controller.viewas = Controller.bits.TREEVIEW + Controller.bits.FOOTVIEW + Controller.bits.SHOWCAPTIONS;
Controller.watch (Controller, 'viewas', function (value, id)
{
    Webservice.persist ('name', 'viewas', 'value', value);
}); 
function show_wait_message (text)
{
    dbody.innerHTML = wait_message (imagecreate('/webservices/images/pinwheel-w.gif')+'<br>'+text);
} 
function wait_message (text)
{
    return '<table width="100%" height="100%"><tr><td align=center>'+text+'</td></tr></table>';
} 
       
function column_set(name, value)
{
    var o=Controller.table.columns;
    for (var x in o)
    {
        if (o[x].originalname==Controller.table.selected)
            o[x][name]=value;
    }
}
 
var bind2Ajax = function (element)
{     
    var records, record, dom, pattern, fieldname, 
        fieldvalue, query, tablename, sql;
    var data     = element.id.split ('.');  
    var value    = element.value;
    var name     = data[0];   
    var index    = data[1];   
    var where    = [];
    if (!(query=Controller.querycollection.selected)) 
        return confirm ( 'Cannot locate query' );
    if (pattern=/SELECT\s+\*\s+FROM\s+(\w+)/i.exec (query.text))
        tablename=pattern[1]; // for right now just support select * from TABLE
    else return confirm (query.text+' does not match the proper pattern.');
    if (!(dom=query.result)) return confirm ( 'Query contains no result' );
    if (!(records=dom.getElementsByTagName ('record'))) 
        return confirm ( 'result contains no records' );  
    if (!(record=records[index])) 
        return confirm ( 'record '+index+' could not be found' );  
    for (var x=0;x<record.childNodes.length;x++)
    { 
        if(record.childNodes[x].nodeName=='field')
        {
            fieldname  = record.childNodes[x].getAttribute ("name");
            fieldvalue = record.childNodes[x].firstChild ? 
                ( "='" + record.childNodes[x].firstChild.nodeValue + "'" ) : 
                ' is null '; 
            if (record.childNodes[x].firstChild) where.push (fieldname + fieldvalue);
        }  
    }
    sql = 'UPDATE ' + tablename + ' SET ' +
          name + '="' + value + '"' +
         ' WHERE ' + where.join (' AND ') ;
    query.update (sql, function (data, id)
    {
        query.setvalue (name, index, value); 
        Event.reload ();
    }); 
} 

var dropmenu = function (element)
{
    var o={
        element  : document.getElementById (element), 
        on       : null, 
        box      : null, 
        items    : [
            {draw : function() {return 'item 1';}},
            {draw : function() {return 'item 2';}},
            {draw : function() {return 'item 3';}},
            {draw : function() {return 'item 4';}}  
        ], 
        display  : function (e) 
        {
            var htm=[];
            for (var x in this.items)
            {
                htm.push (this.items[x].draw());
            }
            var pos =getPosition(this.element);
            this.box.innerHTML = htm.join ('<br>');
            this.box.style.top = (pos.y + this.element.offsetHeight) + 'px';
            this.box.style.left = pos.x + 'px';
            this.box.style.display = 'inline';
            this.on=true;
            
        } , 
        undisplay : function (e)
        { 
            this.box.style.display = 'none';
            this.on=false;
        } , 
        invoke   : function (e)
        { 
            if (e.name=='mousedown'&&e.id==this.element.id) this.display(e); 
            if (e.name=='mouseup'&&this.on) this.undisplay(e); 
        },
        load : function ()
        { 
            makeDraggable (this.element);
            window.mouseDownListener.subscribe (this);
            window.mouseUpListener.subscribe (this);
            window.mouseMoveListener.subscribe (this);
            
            
            var divit = document.createElement('div'); 
            divit.id = this.element.id + '___menu';
            divit.style.position = 'absolute';
            document.body.appendChild(divit);

            this.box=document.getElementById (divit.id);
    
        }
    } 
    
    
    o.load ();
    return o;
}

    
/*
* GLOBAL/DEFAULT PROPERTIES
********************************************************************************************/
var re=/(\w+)\((\d+)\)+/;
var cookie        = {}; 
var PIC_ROOT      = 'http://www.101stratford.com';
var LOGO_URL      = '/webservices/images/yoursql.png';
var DATA_URL      = 'connector.php';
var CONFIG_URL    = 'application.xml'; 
var DATATYPE      = "TINYINT,SMALLINT,MEDIUMINT,INT,INTEGER,BIGINT,REAL,DOUBLE,FLOAT,DECIMAL,NUMERIC,DATE," +               
                    "TIME,TIMESTAMP,DATETIME,CHAR,VARCHAR,TINYBLOB,BLOB,MEDIUMBLOB,LONGBLOB,TINYTEXT,TEXT," +               
                    "MEDIUMTEXT,LONGTEXT";  
DATATYPE=DATATYPE.split (',');
var chk=function(x){ return x?' checked ':''}
var sel=function(x){ return x?' selected ':''}

/*
* WEBSERVICE METHODS
********************************************************************************************/

Webservice.add ('getobjects', Controller.ondatabaseloaded );
Webservice.add ('getobject', Controller.ontable );
Webservice.add ('openobject', Controller.onopen );
Webservice.add ('getfile', Controller.onopen );
Webservice.add ('getpersistance', Controller.oncookie );
Webservice.add ('backupobject', function (x) { alert (x) } );
Webservice.add ('persist', function (x) { /*alert (x)*/ } ); 

function imagecreate (src,width,height) { return '<img '+(width?'width="'+width+'"':'')+' '+(height?'height="'+height+'"':'')+' src="' + PIC_ROOT + src + '" align="absmiddle">'; }


function start ()
{ 

    var tmp = DATA_URL;
    DATA_URL = CONFIG_URL; 
    show_wait_message ('loading configuration...');
    Webservice.getfile ('path', '', function (data) 
    {  
        var dom=XmlDocument.create();   
        if (dom.loadXML (data))  
        {   
            var name, value, add = dom.getElementsByTagName ('database');   
            Controller.databases={count:0};
            Controller.databasename=null;
            for (var x=0;x<add.length;x++)
            {  
                name = add[x].getAttribute ('name');
                Controller.databases[name]=Database.create (name, add[x]);
                Controller.databases.count ++;
            }  
            show_wait_message ('getting cookies...'); 
            Webservice.getpersistance (); 
        } 
    });
    DATA_URL=tmp;
}

function beginRender ()
{
    var name='/';
    tree.add (location.hostname, name);
    tree.items[name].icon=imagecreate ('/101/sql/images/sql.databasi.gif'); 
    for (var x in Controller.databases)
    {
        if (x!='count')
        {
            name = Controller.databases[x].name
            tree.add (name, 'dbo.'+name, '/');
            tree.items['dbo.'+name].icon=imagecreate ('/webservices/images/s_db.png');  
            tree.add ('loading...', name + '/sub', 'dbo.'+name); 
            tree.items[name + '/sub'].icon=imagecreate ('/webservices/images/ico_grid.jpg');  
        }
    } 

    Resizer ('dtree', Controller.treewidth + 'px', 92);
    Resizer ('dbody', 10, 100);
    tree.items['/'].restate();
    
    
    var o = Splitter.create ('tdsplitter');
    var v = Splitter.create ('tdqsplitter');
    o.onchange = function (e)
    {
        Controller.treewidth=e.position.x; Event.reload ();
        Webservice.persist ('name', 'treewidth', 'value', Controller.treewidth/*, function () { Event.reload (); }*/);
    }
    o.onmove = function (e)
    {
        var x = document.getElementById ('dtree');
        x.style.width = e.position.x + 'px';
    }
    v.onchange = function (e)
    {
        Event.reload ();
    }
    v.onmove = function (e)
    {
        var query, pos;
        if (!(query=Controller.querycollection.selected)) return 'No query selected';
        var x = document.getElementById ('tq'+query.key+'');
        pos=getPosition(x);
        query.height = e.position.y - pos.y
        x.style.height = query.height + 'px';
    }

 
    main.invoke();
}



var repeat = function (text, limit) { var o='';for (var x=0;x<limit;x++) o+=text; return o; }
var pad = function (text, limit)
{
    if (limit > 255) limit = 255;
    if (text.length > limit) return text.substr (0,limit);
    return text + repeat (' ', limit - text.length);
}


var nodeconvert = function (node)
{
    var o={},a=node.attributes;for (var i=0;i<a.length;i++) 
    o[a[i].name]=a[i].value;return o;
}

function toolbarlink(src, cmd, caption, pushed)
{ 
    var cell_style    = pushed ? 'border:solid 1px;border-color:#c0c0ff white white #c0c0ff;padding:3px;;background-color:white' : 'border:solid 1px;border-color:white #c0c0ff #c0c0ff white;padding:3px;';
    var link_style    = pushed ? 'font-size:8pt;text-decoration:none;color:#666699' : 'font-size:8pt;color:#333333';
    return '<td style="'+cell_style+';margin:0px" nowrap="nowrap"><a style="'+link_style+';margin:0px" href="javascript:void(0)" onclick=\''+cmd+'\''+
            '><img style="margin:0px" align="absmiddle" border="0" src="'+src+'" onload="window.resizeListener.invoke()">'+(caption?caption:'')+'</a></td>';
}
</script>


<!--.tabon {background:url(http://www.cyber8.net/sites/bg/images/system/button_office_off.jpg);}
.taboff {border:solid 1px;border-color:gray white white gray;background-color:#BEDAFF;}-->

<style>
</style>
</head>

<body style="overflow:hidden" scroll="no" onLoad="start()">
<!-- #BEDAFF <div id="mfile">File</div>-->

 
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="3" height="26" class="tabon" nowrap="nowrap" valign="top"><div id="daddress" style="padding:4px;height:24px;overflow:hidden"></div> </td> 
  </tr> 
  <tr>
    <td class="taboff" valign="top" nowrap="nowrap"><div style="background-color:white" id="dtree"></div></td>
    <td nowrap="nowrap" id="tdsplitter" class="denim"><div id="dsplitter"><img src="/webservices/images/clear.gif" width="8"/></div></td>
    <td class="taboff" valign="top" nowrap="nowrap" width="100%">
     <table border="0" cellpadding="0" cellspacing="0">
      <tr><td colspan="2"><div id="dnavbar"></div></td></tr>
      <tr><td><div id="qbfieldlist"></div></td><td><div id="dquerybar"></div></td></tr>
      <tr><td colspan="2" id="tdqsplitter" class="denim" align="center"><div id="dqsplitter"></div></td></tr>
      <tr><td colspan="2"><div style="background:url(/webservices/images/mysql1.png);background-position:center;background-repeat:no-repeat; background-color:#FFFFFF" id="dbody"></div></td></tr>
     </table>
    </td>
  </tr>
  <tr>
    <td colspan="3" height="1" align="center" nowrap="nowrap" class="denim"><div id="dvsplitter"></div></td> 
  </tr>
</table>
<div id="dfooter" style="border-top:solid 1px #666"></div>
<div id="deditor" style="position:absolute;top:0px;left:0px;display:none"><input style="border:none" class=small id="monkey"/></div>
 
</body>
</html>